/*
    2. Write a program in C to read an existing file. 
    Test Data :
    Input the file name to be opened : test.txt
    Expected Output :

    The content of the file test.txt is  :                                                                       
    This is the content of the file test.txt
*/

#include <stdio.h>
#include <stdlib.h>

#define MAX_LEN 256
#define MAX_STR 1024

int main(void)
{
    FILE *fp;
    char *filename = malloc(MAX_LEN);
    char *str = malloc(MAX_STR);
    printf("Input the file name to be opened : ");
    gets(filename);
    fp = fopen(filename, "r");
    if(!fp){
        printf("Open file %s error!", filename);
        return -1;
    }else{
        if(!fgets(str, MAX_STR, fp)){
            printf("fgets file %s failed!", filename); 
            return -1;
        }else{
            printf("The content of the file %s is : \n%s", filename, str);
        }              
    }

    return 0;
}